<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Seek -- by Phi</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Seek -- by Phi</h1>

<p>Navigating the Start Menu can be a hassle, especially
 if you have installed many programs over time. 'Seek'
 lets you specify a case-insensitive key word/phrase
 that it will use to filter only the matching programs
 and directories from the Start Menu, so that you can
 easily open your target program from a handful of
 matched entries. This eliminates the drudgery of
 searching and traversing the Start Menu.
</p>
<p><a href="Seek_(SearchTheStartMenu).ahk">Download This Script</a> &nbsp;| &nbsp;<a href="index.htm">Other Sample Scripts</a> &nbsp;| &nbsp;<a href="../AutoHotkey.htm">Home</a></p>

<pre class="NoIndent"><em>;*****************************************************************
;
;  Program : Seek
;  Coder   : Phi
;  Updated : Mon Jan 31 10:08:37 2005
;
;  What do you seek, my friend?
;
;*****************************************************************
;
;  I have a lot of fun coding this, and hope you will
;  enjoy using it too. Feel free to drop me an email with
;  your comments and feedback at: phi1618 (*a.t*) gmail
;  :D0T: com.
;
;  Options:
;    -cache Use the cached directory-listing if available
;           (this is the default mode when no option is specified)
;    -scan  Force a directory scan to retrieve the latest
;           directory listing
;    -scex  Scan &amp; exit (this is useful for scheduling the
;           potentially time-consuming directory-scanning as
;           a background job)
;    -help  Show this help
;
;*****************************************************************
;
; HOW TO 'SEEK':
;
; 1. 'Seek' is an AutoHotkey script. You can either run it
;    as Seek.ahk (original script) or Seek.exe (compiled
;    executable).
;
;    To obtain Seek.exe, you can download Seek.zip (includes
;    both the source code and the compiled binary) from
;    http://home.ripway.com/2004-10/188589/
;    Otherwise, you can compile Seek.ahk on your own by
;    using AutoHotkey's Ahk2Exe.exe compiler, or you can
;    ask me for a copy via email. The filesize is small at
;    about 200 kbytes. I can be reached at: phi1618 (*a.t*)
;    gmail :D0T: com.
;
;    To use Seek.ahk, first, you'll need to install
;    AutoHotkey v1.0.25 or higher on your PC (download from
;    http://www.autohotkey.com). Next, run the command:
;
;    X:\myTools\AutoHotkey\AutoHotkey.exe Y:\myAHK\Seek.ahk
;
;    Remember to replace X:\myTools and Y:\myAHK with
;    the proper directory names on your PC.
;
; 2. You can place the executable Seek.exe anywhere you
;    want. There is no installation required, it doesn't
;    write anything to your registry, and it doesn't
;    access the Internet at all (no phoning home). To
;    uninstall, simply delete Seek.exe.
;
;    The only 2 files 'Seek' creates are placed in your
;    TMP directory:
;
;      a. _Seek.key  (cache file for last query string)
;      b. _Seek.list (cache file for directory listing)
;
;    If you're a purist, you can delete them manually
;    when you decide to remove 'Seek' from your system.
;
; 3. The most convenient way to run 'Seek' is via a
;    shortcut/hotkey. If you are not already using any
;    hotkey management program on your PC, I highly
;    recommend AutoHotkey. If you don't intend to install
;    any hotkey management program at the moment, you can
;    make use of Windows shortcut feature and bind a
;    shortcut key (e.g. ALT-F1) to launch 'Seek'. This is
;    important so that you can run 'Seek' at anytime and
;    anywhere.
;
; 4. When you run 'Seek' for the first time, it'll scan
;    your Start Menu, and save the directory listing into
;    a cache file.
;
;    The following directories are included in the scanning:
;    - %A_StartMenu%
;    - %A_StartMenuCommon%
;
;    By default, subsequent runs will read from the
;    cache file so as to reduce the loading time. For
;    more info on options, run 'Seek.exe -help'. If you
;    think your Start Menu doesn't contain too many
;    programs, you can choose not to use the cache and
;    instruct 'Seek' to always do a directory scan (via
;    option -scan).  That way, you will always get the
;    latest listing.
;
; 5. When you run 'Seek', a window will appear, waiting
;    for you to enter a key word/phrase. After you have
;    entered a query string, a list of matching records
;    will be displayed. Next, you need to highlight an
;    entry and press &lt;Enter&gt; or click on the 'Open'
;    button to run the selected program or open the
;    selected directory.
;
;*****************************************************************
;
; TECHNICAL NOTES:
;
; - 'Seek' requires Chris Mallett's AutoHotkey v1.0.25
;   or higher version (http://www.autohotkey.com).
;   Thanks to Chris for his great work on AutoHotkey. :)
;
; - The following environment variables must be valid:
;   a. TMP
;
;*****************************************************************
;
; KNOWN PROBLEMS:
;
; - Nil
;
;*****************************************************************
;
; IMPLEMENTED SUGGESTIONS:
;
; - Highlight 1st matching record by default so that
;   user can just hit &lt;Enter&gt; to run it.
;   (Suggested by Yih Yeong)
;
; - Enable double-click on the listing of the search
;   results to launch the program.
;   (Suggested by Yih Yeong &amp; Jack)
;
; - Auto real-time incremental search.
;   (Suggested by Rajat)
;
; - Fuzzy search when user enters multiple query strings,
;   separated by space.
;   (Suggested by Rajat)
;
;*****************************************************************
;
; SUGGESTED FEATURES (MAY OR MAY NOT BE IMPLEMENTED):
;
; - Log the launch history. List the most frequently
;   used programs at the top of the search results.
;   (Suggested by Yih Yeong)
;
; - Instead of using list box, can it display a series
;   of application icons so that hovering the cursor
;   over the icon will display a tooltip containing the
;   program information (path, etc).
;   (Suggested by Yih Yeong)
;
; - Instead of matching text in the middle, match only
;   those program/directory names that begin with the
;   query string.
;   (Suggested by Stefan)
;
; - Add favorites management. Launch group of programs
;   in a single run.
;   (Suggested by Atomhrt)
;
; - Integrate Seek into the Windows taskbar/toolbar so that
;   it is always available and there is no need to bind a
;   hotkey to launch Seek.
;   (Suggested by Deniz Akay)
;
; - Search by wildcards/regex.
;   (Suggested by Steve)
;
;*****************************************************************
;
; CHANGE HISTORY:
;
; * v1.1.0
; - Initial release.
;
; * v1.1.1
; - Removed maximise-window option since some programs don't
;   function well with it.
; - Added double-click detection to trigger 'Open' function.
;
; * v2.0.0
; - Integrated the 'Seek' popup window into the output screen
;   so that user can re-enter the query string to search for
;   something else without having to exit and run Seek again.
; - Added 'Scan Start-Menu' button.
; - Added real-time incremental search which will auto
;   filter for matching records while you type away,
;   without waiting for you to press &lt;Enter&gt;.
; - Added internal switch (TrackKeyPhrase) to track search-string.
; - Added internal switch (ToolTipFilename) to show filename
;   using tooltip.
;
; * v2.0.1
; - Added horizontal scrollbar to ListBox so that very
;   long records will not be cut-off in the middle.
;
; * v2.0.2
; - Allowed user to add their own customised list of directories
;   to be included in the scanning. User just needs to create a
;   text file 'Seek.dir' in the same directory as Seek.exe or
;   Seek.ahk, and specify the full path of the directory to be
;   added, one directory per line. Do not enclose the path in
;   quotes or double-quotes.
;
; * v2.0.3
; - Added /on option to DIR-command to sort by name.
; - Fuzzy search when user enters multiple query strings,
;   separated by space, for e.g. &quot;med pla&quot;. It's a match
;   when all the strings (&quot;med&quot; &amp; &quot;pla&quot;) are found. This
;   will match &quot;Media Player&quot;, &quot;Macromedia Flash Player&quot;,
;   &quot;Play Medieval King&quot;, &quot;medpla&quot;, &quot;plamed&quot;.
; - Corrected tab-movement sequence by adding all buttons
;   right from the start, but disable them until they can
;   be used.
; - Added status bar to replace tooltip-feedback.
; - Removed obsolete internal switch (ToolTipFilename).
; - Replaced the use of &quot;dir&quot; command with AutoHotkey's
;   own &quot;Loop&quot; command for scanning directory contents.
;   &quot;dir&quot; cannot handle extended character set and thus
;   non-English (e.g German) directory and filename are
;   captured wrongly. (Thanks Wolfgang Bujatti and
;   Sietse Fliege for testing this modification)
; - Added internal switch (ScanMode) to define whether
;   files and/or directories are to be included in scan.
; - Replaced hardcoded directory paths of Start Menu with
;   built-in variables A_StartMenu, A_StartMenuCommon.
;   With this, Seek now works for different locales with
;   different naming convention of the Start Menu.
;   (Thanks Wolfgang Bujatti and Sietse Fliege for help
;   in testing another method before these new variables
;   are available.)
; - Added the pre-selection of the last-run program
;   record so that a quick double-&lt;ENTER&gt; will run it.
;
;*****************************************************************</em>

<em>;**************************
;&lt;--- BEGIN OF PROGRAM ---&gt;
;**************************</em>

<em>;==== Your Customisation ===================================</em>

<em>; Specify which program to use when opening a directory.
; If the program cannot be found or is not specified
; (i.e. variable is unassigned or assigned a null value),
; the default Explorer will be used.</em>
dirExplorer = E:\utl\xplorer2_lite\xplorer2.exe

<em>; User's customised list of additional directories to be
; included in the scanning. The full path must not be
; enclosed by quotes or double-quotes. If this file is
; missing, only the default directories will be scanned.</em>
SeekMyDir = %A_ScriptDir%\Seek.dir

<em>; Specify the filename and directory location to save
; the cached directory/program listing. There is no
; need to change this unless you want to.</em>
dirListing = %A_Temp%\_Seek.list

<em>; Specify the filename and directory location to save
; the cached key word/phrase of last search. There is
; no need to change this unless you want to.</em>
keyPhrase = %A_Temp%\_Seek.key

<em>; Track search string (ON/OFF)
; If ON, the last-used query string will be re-used as
; the default query string the next time you run Seek.
; If OFF, the last-used query string will not be tracked
; and there will not be a default query string value the
; next time you run Seek.</em>
TrackKeyPhrase = ON

<em>; Specify what should be included in scan.
; 0: Directories are excluded (only files).
; 1: All files and directories are included.
; 2: Only directories are included (no files).</em>
ScanMode = 1

<em>;...........................................................</em>

<em>; INIT
;#NoTrayIcon</em>
StringCaseSense, Off
version = Seek v2.0.3

<em>; DISPLAY HELP INSTRUCTIONS</em>
If 1 in --help,-help,/h,-h,/?,-?
{
    MsgBox,, %version%, Navigating the Start Menu can be a hassle, especially if you have installed many programs over time. 'Seek' lets you specify a case-insensitive key word/phrase that it will use to filter only the matching programs and directories from the Start Menu, so that you can easily open your target program from a handful of matched entries. This eliminates the drudgery of searching and traversing the Start Menu.`n`nI have a lot of fun coding this, and hope you will enjoy using it too. Feel free to drop me an email with your comments and feedback at: phi1618 (*a.t*) gmail :D0T: com.`n`nOptions:`n  -cache`tUse the cached directory-listing if available (this is the default mode when no option is specified)`n  -scan`tForce a directory scan to retrieve the latest directory listing`n  -scex`tScan &amp; exit (this is useful for scheduling the potentially time-consuming directory-scanning as a background job)`n  -help`tShow this help
    Goto QuitNoSave
}

<em>; CHECK THAT THE MANDATORY ENVIRONMENT VARIABLES EXIST AND ARE VALID
; *TMP*</em>
IfNotExist, %A_Temp% <em>; PATH DOES NOT EXIST</em>
{
    MsgBox This mandatory environment variable is either not defined or invalid:`n`n    TMP = %A_Temp%`n`nPlease fix it before running Seek.
    Goto QuitNoSave
}

<em>; IF NOT SCAN-AND-EXIT</em>
IfNotEqual 1, -scex
{
    <em>; RETRIEVE THE LAST USED KEY-PHRASE FROM CACHE FILE</em>
    <em>; TO BE USED AS THE DEFAULT QUERY STRING</em>
    If TrackKeyPhrase = ON
    {
        FileReadLine, PrevKeyPhrase, %keyPhrase%, 1
        FileReadLine, PrevOpenTarget, %keyPhrase%, 2
    }
    NewKeyPhrase = %PrevKeyPhrase%
    NewOpenTarget = %PrevOpenTarget%

    <em>; ADD THE TEXT BOX FOR USER TO ENTER THE QUERY STRING</em>
    Gui, 1:Add, Edit, vFilename W600, %NewKeyPhrase%

    <em>; ADD MY FAV TAGLINE</em>
    Gui, 1:Add, Text, X625 Y10, What do you seek, my friend?

    <em>; ADD THE STATUS BAR FOR PROVIDING FEEDBACK TO USER</em>
    Gui, 1:Add, Text, vStatusBar X10 Y31 R1 W764

    <em>; ADD THE SELECTION LISTBOX FOR DISPLAYING SEARCH RESULTS</em>
    Gui, 1:Add, ListBox, vOpenTarget gTargetSelection X10 Y53 R28 W764 HScroll Disabled, %List%

    <em>; ADD THESE BUTTONS, BUT DISABLE THEM FOR NOW</em>
    Gui, 1:Add, Button, gButtonOPEN vButtonOPEN Default X10 Y446 Disabled, Open
    Gui, 1:Add, Button, gButtonOPENDIR vButtonOPENDIR X59 Y446 Disabled, Open Directory
    Gui, 1:Add, Button, gButtonSCANSTARTMENU vButtonSCANSTARTMENU X340 Y446 Disabled, Scan Start-Menu

    <em>; ADD THE EXIT BUTTON</em>
    Gui, 1:Add, Button, gButtonEXIT X743 Y446, Exit

    <em>; POP-UP THE QUERY WINDOW</em>
    Gui, 1:Show, Center, %version%
}

<em>; ENABLE RE-SCANNING OF LATEST DIRECTORY LISTING</em>
If 1 in -scan,-scex
    rescan = Y
<em>; CHECK WHETHER THE DIRECTORY LISTING CACHE FILE ALREADY EXISTS. IF NOT, DO A RE-SCAN.</em>
Else IfNotExist, %dirListing%
    rescan = Y

If rescan = Y <em>; DO A RE-SCAN</em>
{
    <em>; SHOW STATUS UNLESS USER SPECIFIES SCAN-AND-EXIT OPTION</em>
    IfNotEqual 1, -scex
        GuiControl,, StatusBar, Scanning directory listing...

    <em>; SCAN START-MENU AND STORE DIRECTORY/PROGRAM LISTINGS IN CACHE FILE</em>
    Gosub ScanStartMenu

    <em>; QUIT IF USER SPECIFIES SCAN-AND-EXIT OPTION</em>
    IfEqual 1, -scex, Goto, QuitNoSave
}

GuiControl,, StatusBar, Retrieving last query result...

<em>; RETRIEVE THE MATCHING LIST FOR THE LAST USED KEY-PHRASE</em>
Gosub SilentFindMatches

<em>; REMOVE THE STATUS TEXT</em>
GuiControl,, StatusBar,

<em>; DIRECTORY LISTING IS NOW LOADED. ENABLE THE OTHER BUTTONS.
; THESE BUTTONS ARE DISABLED EARLIER BECAUSE THEY SHOULD NOT
; BE FUNCTIONAL UNTIL THIS PART OF THE SCRIPT.</em>
GuiControl, 1:Enable, ButtonOPEN
GuiControl, 1:Enable, ButtonOPENDIR
GuiControl, 1:Enable, ButtonSCANSTARTMENU

<em>; TURN ON INCREMENTAL SEARCH</em>
SetTimer, tIncrementalSearch, 500

<em>; REFRESH THE GUI</em>
Gosub EnterQuery

Return

<em>;***********************************************************
;                                                          *
;                 END OF MAIN PROGRAM                      *
;                                                          *
;***********************************************************</em>


<em>;=== BEGIN ButtonSCANSTARTMENU EVENT =======================</em>

ButtonSCANSTARTMENU:

Gui, 1:Submit, NoHide
GuiControl,, StatusBar, Scanning directory listing...

<em>; DISABLE LISTBOX WHILE SCANNING IS IN PROGRESS</em>
GuiControl, 1:Disable, OpenTarget
GuiControl, 1:Disable, ButtonEXIT
GuiControl, 1:Disable, ButtonOPEN
GuiControl, 1:Disable, ButtonOPENDIR
GuiControl, 1:Disable, ButtonSCANSTARTMENU

<em>; DO THE SCANNING</em>
Gosub ScanStartMenu

<em>; INFORM USER THAT SCANNING HAS COMPLETED</em>
If Filename =
{
    <em>; IF QUERY STRING IS EMPTY...</em>
    GuiControl, 1:Enable, ButtonEXIT
    GuiControl, 1:Enable, ButtonOPEN
    GuiControl, 1:Enable, ButtonSCANSTARTMENU
    GuiControl,, StatusBar, Scan completed.
    Gosub EnterQuery
}
Else
{
    <em>; IF QUERY STRING EXISTS...</em>
    <em>; FILTER FOR SEARCH STRING WITH THE NEW LISTING</em>
    NewKeyPhrase =
    Gosub FindMatches
}
Return

<em>;... END ButtonSCANSTARTMENU EVENT .........................</em>


<em>;=== BEGIN ScanStartMenu SUBROUTINE ========================
; SCAN THE START-MENU AND STORE THE DIRECTORY/PROGRAM
; LISTINGS IN A CACHE FILE</em>
ScanStartMenu:

<em>; DEFINE THE DIRECTORY PATHS TO RETRIEVE.
; THE PATH MUST NOT BE ENCLOSED BY QUOTES OR DOUBLE-QUOTES.
;
; FOR ENGLISH VERSION OF WINDOWS</em>
scanPath = %A_StartMenu%|%A_StartMenuCommon%

<em>; INCLUDE ADDITIONAL USER-DEFINED PATHS FOR SCANNING</em>
IfExist, %SeekMyDir%
{
    Loop, read, %SeekMyDir%
    {
        IfNotExist, %A_LoopReadLine%
            MsgBox, 8192, %version%, Processing your customised directory list...`n`n&quot;%A_LoopReadLine%&quot; does not exist and will be excluded from the scanning.`nPlease update [ %SeekMyDir% ].
        Else
            scanPath = %scanPath%|%A_LoopReadLine%
    } 
}

<em>; DELETE EXISTING FILE BEFORE CREATING A NEW VERSION</em>
FileDelete, %dirListing%

<em>; SCAN DIRECTORY LISTING (DELIMITER = |) BY RECURSING
; EACH DIRECTORY TO RETRIEVE THE CONTENTS. HIDDEN FILES
; ARE EXCLUDED.</em>
Loop, parse, scanPath, |
{
    Loop, %A_LoopField%\*, %ScanMode%, 1
    {
        FileGetAttrib, fileAttrib, %A_LoopFileFullPath%
        IfNotInString, fileAttrib, H <em>; EXCLUDE HIDDEN FILE</em>
            FileAppend, %A_LoopFileFullPath%`n, %dirListing%
    }
}

Return

<em>;... END ScanStartMenu SUBROUTINE ..........................</em>


<em>;=== BEGIN FindMatches SUBROUTINE ==========================
; SEARCH AND DISPLAY ALL MATCHING RECORDS IN THE LISTBOX</em>
FindMatches:

Gui, 1:Submit, NoHide
CurFilename = %Filename%
GuiControl,, StatusBar, 

<em>; CHECK FOR EMPTY QUERY STRING</em>
If CurFilename =
{
    MsgBox, 8192, %version%, Please enter the key word/phrase to search for.
    Goto EnterQuery
}

<em>; tIncrementalSearch IS BEING INTERRUPTED. LET IT FINISHES.</em>
If NewKeyPhrase &lt;&gt; %CurFilename%
{
    <em>; INFORM USER THAT PATIENCE IS A VIRTUE</em>
    GuiControl,, StatusBar, Seeking...
    ResumeFindMatches = TRUE
    Return
}

If List = |
{
    <em>; NOT EVEN A SINGLE MATCHING RECORD IS FOUND.</em>
    <em>; LET USER MODIFY THE QUERY STRING AND TRY AGAIN.</em>
    MsgBox, 8192, %version%, The query string &quot;%CurFilename%&quot; does not match any record. Try again.
    GuiControl, 1:Disable, ButtonOPENDIR
    GuiControl, 1:Enable, ButtonSCANSTARTMENU
    Goto EnterQuery
}
Else
{
    <em>; SELECT THE FIRST RECORD IF NO OTHER RECORD HAS BEEN SELECTED</em>
    Gui, 1:Submit, NoHide
    GuiControl, 1:Enable, OpenTarget
    GuiControl, 1:Enable, ButtonOPEN
    GuiControl, 1:Enable, ButtonOPENDIR
    GuiControl, 1:Enable, ButtonSCANSTARTMENU
    GuiControl, Focus, OpenTarget
    If OpenTarget =
        GuiControl, 1:Choose, OpenTarget, |1
}

<em>; REFRESH GUI</em>
Gui, 1:Show, Center, %version%

Return

<em>;... END FindMatches SUBROUTINE ............................</em>


<em>;=== BEGIN SilentFindMatches SUBROUTINE ====================</em>

SilentFindMatches:

Gui, 1:Submit, NoHide
sfmFilename = %Filename%

<em>; FILTER MATCHING RECORDS BASED ON USER QUERY STRING</em>
List = |
If sfmFilename &lt;&gt;
{
    Loop, read, %dirListing%
    {
        Gui, 1:Submit, NoHide
        tFilename = %Filename%
        If sfmFilename &lt;&gt; %tFilename%
        {
            <em>; USER HAS CHANGED THE SEARCH STRING. THERE IS NO POINT</em>
            <em>; TO CONTINUE SEARCHING USING THE OLD STRING, SO ABORT.</em>
            Return
        }
        Else
        {
            <em>; APPEND MATCHING RECORDS INTO THE LIST</em>
            SplitPath, A_LoopReadLine, name, dir, ext, name_no_ext, drive
            MatchFound = Y
            Loop, parse, sfmFilename, %A_Space%
            {
                IfNotInString, name, %A_LoopField%
                {
                    MatchFound = N
                    Break
                }
            }
            IfEqual, MatchFound, Y
            {
                <em>; ADD RECORD TO LIST</em>
                List = %List%%A_LoopReadLine%|

                <em>; PRE-SELECT IF THIS MATCHES THE LAST-RUN PROGRAM</em>
                If (A_LoopReadLine = PrevOpenTarget &amp;&amp; sfmFilename = PrevKeyPhrase)
                    List = %List%|
            }
        }
    }
}

<em>; REFRESH LIST WITH SEARCH RESULTS</em>
GuiControl, 1:, OpenTarget, %List%

If List = |
{
    <em>; NO MATCHING RECORD IS FOUND</em>
    <em>; DISABLE LISTBOX</em>
    GuiControl, 1:Disable, OpenTarget
    GuiControl, 1:Disable, ButtonOPENDIR
}
Else
{
    <em>; MATCHING RECORDS ARE FOUND</em>
    <em>; ENABLE LISTBOX</em>
    GuiControl, 1:Enable, OpenTarget
    GuiControl, 1:Enable, ButtonOPENDIR
}

<em>; REFRESH GUI</em>
Gui, 1:Show, Center, %version%

Return

<em>;... END SilentFindMatches SUBROUTINE ......................</em>


<em>;=== BEGIN EnterQuery SUBROUTINE ===========================
; REFRESH GUI AND LET USER ENTERS SEARCH STRING</em>
EnterQuery:
GuiControl, Focus, Filename
GuiControl, 1:Enable, ButtonOPEN
Gui, 1:Show, Center, %version%
Return
<em>;... END EnterQuery SUBROUTINE .............................</em>


<em>;=== BEGIN TargetSelection EVENT ===========================</em>

TargetSelection:
Gui, 1:Submit, NoHide

<em>; DOUBLE-CLICK DETECTION TO LAUNCH PROGRAM</em>
If A_GuiControlEvent = DoubleClick
{
    Gosub ButtonOPEN
}
Else
{
    <em>; STUB - FOR FUTURE USE</em>
    If A_GuiControlEvent = Normal
    {
        <em>; DO NOTHING FOR NOW</em>
    }
}

Return

<em>;... END TargetSelection EVENT .............................</em>


<em>;=== BEGIN ButtonOPEN EVENT ================================</em>

<em>; USER CLICKED ON 'OPEN' BUTTON OR PRESSED &lt;ENTER&gt;</em>
ButtonOPEN:
Gui, 1:Submit, NoHide

<em>; FIND OUT WHERE THE KEYBOARD FOCUS WAS. IF IT'S THE
; TEXT FIELD, RUN THE QUERY TO FIND MATCHES. ELSE, IT
; MUST BE FROM THE LISTBOX.</em>
GuiControlGet, focusControl, 1:Focus
If focusControl = Edit1
{
    GuiControl, Focus, OpenTarget
    GuiControl, 1:Disable, OpenTarget
    GuiControl, 1:Disable, ButtonOPENDIR
    GuiControl, 1:Disable, ButtonSCANSTARTMENU
    Goto FindMatches
}

<em>; NO RECORD FROM THE LISTBOX IS SELECTED</em>
If OpenTarget =
{
    MsgBox, 8192, %version%, Please make a selection before hitting &lt;Enter&gt;.`nPress &lt;Esc&gt; to exit.
    Goto EnterQuery
}

<em>; SELECTED RECORD DOES NOT EXIST (FILE OR DIRECTORY NOT FOUND)</em>
IfNotExist, %OpenTarget%
{
    MsgBox, 8192, %version%, %OpenTarget% does not exist. This means that the directory cache is outdated. You may click on the 'Scan Start-Menu' button below to update the directory cache with your latest directory listing now.
    Goto EnterQuery
}

<em>; CHECK WHETHER THE SELECTED RECORD IS A FILE OR DIRECTORY</em>
FileGetAttrib, fileAttrib, %OpenTarget%
IfInString, fileAttrib, D <em>; IS DIRECTORY</em>
{
    Gosub sOpenDir
}
Else If fileAttrib &lt;&gt; <em>; IS FILE</em>
{
    Run, %OpenTarget%
}
Else
{
    MsgBox %OpenTarget% is neither a DIRECTORY or a FILE. This shouldn't happen. Seek cannot proceed. Quitting...
}

Goto Quit

<em>;... END ButtonOPEN EVENT ..................................</em>


<em>;=== BEGIN ButtonOPENDIR EVENT =============================</em>

<em>; USER CLICKED ON 'OPEN DIRECTORY' BUTTON</em>
ButtonOPENDIR:
Gui, 1:Submit, NoHide

<em>; CHECK THAT USER HAS SELECTED A RECORD ALREADY</em>
If OpenTarget =
{
    MsgBox, 8192, %version%, Please make a selection first.
    Goto EnterQuery
}

<em>; RUN SUBROUTINE TO OPEN A DIRECTORY</em>
Gosub sOpenDir

Goto Quit

<em>;... END ButtonOPENDIR EVENT ...............................</em>


<em>;=== BEGIN sOpenDir SUBROUTINE =============================</em>

sOpenDir:

<em>; IF USER SELECTED A FILE-RECORD INSTEAD OF A DIRECTORY-RECORD,
; EXTRACT THE DIRECTORY PATH. (I'M USING DriveGet INSTEAD OF
; FileGetAttrib TO ALLOW THE SCENARIO WHEREBY OpenTarget IS
; INVALID BUT THE DIRECTORY PATH OF OpenTarget IS VALID.</em>
DriveGet, status, status, %OpenTarget%
If status &lt;&gt; Ready <em>; NOT A DIRECTORY</em>
{
    SplitPath, OpenTarget, name, dir, ext, name_no_ext, drive
    OpenTarget = %dir%
}

<em>; CHECK WHETHER DIRECTORY EXISTS</em>
IfNotExist, %OpenTarget%
{
    MsgBox, 8192, %version%, %OpenTarget% does not exist. This means that the directory cache is outdated. You may click on the 'Scan Start-Menu' button below to update the directory cache with your latest directory listing now.
    Goto EnterQuery
}

<em>; OPEN THE DIRECTORY</em>
IfExist, %dirExplorer%
{
    Run, &quot;%dirExplorer%&quot; &quot;%OpenTarget%&quot;, , Max <em>; OPEN WITH CUSTOMISED FILE EXPLORER</em>
}
Else
{
    Run, %OpenTarget%, , Max <em>; OPEN WITH DEFAULT WINDOWS FILE EXPLORER</em>
}
Return

<em>;... END sOpenDir SUBROUTINE ...............................</em>


<em>;=== BEGIN tIncrementalSearch EVENT ========================
; AUTOMATICALLY CONDUCT REAL-TIME INCREMENTAL SEARCH
; TO FIND MATCHING RECORDS WITHOUT WAITING FOR USER
; TO PRESS &lt;ENTER&gt;</em>
tIncrementalSearch:

Loop
<em>; REPEAT SEARCHING UNTIL USER HAS STOPPED CHANGING THE QUERY STRING</em>
{
    Gui, 1:Submit, NoHide
    CurFilename = %Filename%
    If NewKeyPhrase &lt;&gt; %CurFilename%
    {
        OpenTarget =
        Gosub SilentFindMatches
        NewKeyPhrase = %CurFilename%
        Sleep, 100 <em>; DON'T HOG THE CPU!</em>
    }
    Else
    {
        <em>; QUERY STRING HAS STOPPED CHANGING</em>
        Break
    }
}

<em>; USER HAS HIT &lt;ENTER&gt; TO LOOK FOR MATCHING RECORDS.
; RUN FindMatches NOW.</em>
If ResumeFindMatches = TRUE
{
    ResumeFindMatches = FALSE
    Gosub FindMatches
}

<em>; CONTINUE MONITORING FOR CHANGES</em>
SetTimer, tIncrementalSearch, 500

Return

<em>;... END tIncrementalSearch EVENT ..........................</em>


<em>;=== BEGIN Quit SUBROUTINE =================================</em>

Quit:
ButtonEXIT:
GuiClose:
GuiEscape:

Gui, 1:Submit, NoHide

<em>; SAVE THE KEY WORD/PHRASE FOR NEXT RUN IF IT HAS CHANGED</em>
If TrackKeyPhrase = ON
{
    If (PrevKeyPhrase &lt;&gt; Filename || PrevOpenTarget &lt;&gt; OpenTarget)
    {
        FileDelete, %keyPhrase%
        FileAppend, %Filename%`n, %keyPhrase%
        FileAppend, %OpenTarget%`n, %keyPhrase%
    }
}

QuitNoSave:
ExitApp <em>; JOB DONE. G'DAY!</em>

<em>;... END Quit SUBROUTINE ...................................</em>


<em>;************************
;&lt;--- END OF PROGRAM ---&gt;
;************************</em>

<em>; /* vim: set noexpandtab shiftwidth=4: */</em>
</pre>
</body>
</html>
